package cn.htsyb.synergy.orm.jpa.repository;

import cn.htsyb.synergy.orm.constant.ValidStatus;
import cn.htsyb.synergy.orm.jpa.model.entity.AbsIdStatusEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.query.Param;
import org.springframework.lang.Nullable;

import java.io.Serializable;

/**
 * @author lakeside hubin_yuan.410@hotmail.com
 * @version V1.0.0
 * @date 2022/5/11
 * @since 1.0
 */
@NoRepositoryBean
public interface IJpaCommonRepository<T extends AbsIdStatusEntity, ID> extends Serializable, JpaRepository<T, ID>, JpaSpecificationExecutor<T> {

    /**
     * 物理删除
     *
     * @param iterable
     */
    void deleteByIdIn(@Nullable @Param("ids") Iterable<ID> iterable);

    /**
     * 变更状态
     * @param validStatus
     * @param iterable
     */
    @Modifying
    @Query(value = "update #{#entityName} ent set ent.validStatus=:validStatus where ent.id in(:ids)")
    void updateValidStatus(@Param("validStatus") ValidStatus validStatus, @Nullable @Param("ids") Iterable<ID> iterable);

}
